package com.csw.android.doubanslidedemo.slide.test

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.csw.android.doubanslidedemo.R

class TestActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_test)

        findViewById<RecyclerView>(R.id.recyclerView)?.run {
            layoutManager = LinearLayoutManager(context)
            adapter = object : RecyclerView.Adapter<VH>() {
                val data = IntArray(30) {
                    return@IntArray it + 1
                }

                override fun onCreateViewHolder(
                    parent: ViewGroup,
                    viewType: Int
                ): VH {
                    val view = LayoutInflater.from(parent.context)
                        .inflate(android.R.layout.simple_list_item_1, parent, false)
                    return VH(view)
                }

                override fun onBindViewHolder(holder: VH, position: Int) {
                    holder.text.setText("fg${data[position]}")
                }

                override fun getItemCount(): Int {
                    return data.size
                }
            }
        }
    }

    private inner class VH(view: View) : RecyclerView.ViewHolder(view) {
        var text: TextView

        init {
            text = view.findViewById(android.R.id.text1)
        }
    }

}